package com.roadmap.struts.action.admin.sns;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.roadmap.biz.common.IManager;
import com.roadmap.biz.common.ManagerFactory;
import com.roadmap.cache.RdcSessionCache;
import com.roadmap.common.RdcConst;
import com.roadmap.struts.action.ActionConst;
import com.roadmap.struts.action.RdcAction;

public class RequestAction extends RdcAction {

	public RequestAction() {
		super(null);
	}

	@Override
	public ActionForward performAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();
		// this action can be executed only by the owner not other people
		String currentUser = getUIDFromSession(request);
		IManager mgr = ManagerFactory.getInstance(RdcConst.REQUEST,
				currentUser);
		List reqs = mgr.getEntitiesOfOwner();
		if (reqs != null && !reqs.isEmpty()) {
			request.setAttribute("requests", reqs);

			// after the request data was loaded, set the request count stored
			// in session to 0
			RdcSessionCache cache = (RdcSessionCache) session
					.getAttribute(ActionConst.RDC_SESSION_CACHE_NAME);
			cache.setRequestCount(0);
		}
		return mapping.findForward("getreq");
	}

}
